unit ufrmMain;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, RzPanel, ExtCtrls, RzTabs, RzSplit, RzStatus, ImgList, StdCtrls,
  RzGroupBar, jpeg;

type
  TfrmMain = class(TForm)
    TopPanel: TRzPanel;
    StatusBar: TRzStatusBar;
    RzSplitter1: TRzSplitter;
    BusinessPanel: TRzPanel;
    WorkPage: TRzPageControl;
    MainPage: TRzTabSheet;
    RzPageControl1: TRzPageControl;
    TabSheet1: TRzTabSheet;
    Image1: TImage;
    Label1: TLabel;
    ImageList1: TImageList;
    ImageList2: TImageList;
    RzStatusPane1: TRzStatusPane;
    RzGroupBar1: TRzGroupBar;
    RzGroup1: TRzGroup;
    Label2: TLabel;
    RzGroup2: TRzGroup;
    RzGroup3: TRzGroup;
    RzGroup4: TRzGroup;
    procedure RzGroup1Items0Click(Sender: TObject);
    procedure WorkPageMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure RzGroup1Items1Click(Sender: TObject);
    procedure RzGroup3Items1Click(Sender: TObject);
    procedure RzGroup3Items0Click(Sender: TObject);
    procedure RzGroup2Items0Click(Sender: TObject);
    procedure RzGroup2Items1Click(Sender: TObject);
    procedure RzGroup1Items2Click(Sender: TObject);
  private
    procedure ShowForm(PageControl:TRzPageControl;FormClass:TFormClass;Caption:String);
    procedure CloseSheet(TabSheet:TRzTabSheet);
    function  FindEqualForm(FormClass:TFormClass;PageControl:TRzPageControl):Boolean;
  public

  end;

var
  frmMain: TfrmMain;

implementation
    uses ufrmDataSearcher,UfrmGhouseSimulate,UfrmWordFactory,UfrmSmsFactory,
         UfrmCropKPI,UfrmWeatherKPI,UfrmSimuArith;
{$R *.dfm}

procedure TfrmMain.CloseSheet(TabSheet: TRzTabSheet);
begin
    if TabSheet.Name<>'MainPage' then
     TabSheet.Free;
end;

function TfrmMain.FindEqualForm(FormClass: TFormClass;
  PageControl: TRzPageControl): Boolean;
  var i:Integer;

begin

   Result := False;
   for i := PageControl.PageCount - 1 downto 1 do
      if TForm(PageControl.Pages[i].Tag) is FormClass then
        begin
        Result := True;
        PageControl.ActivePageIndex:=i;
        end;
end;





procedure TfrmMain.RzGroup1Items0Click(Sender: TObject);
begin
   showform(WorkPage,TfrmDataSearcher,TRzGroupItem(Sender).Caption);
end;

procedure TfrmMain.ShowForm(PageControl: TRzPageControl;
  FormClass: TFormClass; Caption: String);
   var Form:TForm;
       TabSheet:TRzTabSheet;
begin
   if FindEqualForm(FormClass,PageControl) then Exit;
   TabSheet:=TRzTabSheet.Create(PageControl);
   TabSheet.PageControl:= PageControl;
   TabSheet.Caption:=Caption;
   Form:=FormClass.Create(TabSheet);
   form.Parent:=TabSheet;
   TabSheet.Tag:=Integer(Form);
   PageControl.ActivePage:=TabSheet;
   Form.Left:=PageControl.Left;
   Form.Top:=PageControl.Top;
   Form.Show;
end;

procedure TfrmMain.WorkPageMouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
   if(Button= mbleft) and (ssDouble in Shift) then
      CloseSheet(TRzPageControl(Sender).ActivePage);
end;

procedure TfrmMain.RzGroup1Items1Click(Sender: TObject);
begin
   showform(WorkPage,TfrmGhouseSimulate,TRzGroupItem(Sender).Caption);
end;

procedure TfrmMain.RzGroup3Items1Click(Sender: TObject);
begin
   showform(WorkPage,TfrmSmsFactory,TRzGroupItem(Sender).Caption);
end;

procedure TfrmMain.RzGroup3Items0Click(Sender: TObject);
begin
   showform(WorkPage,TfrmWordFactory,TRzGroupItem(Sender).Caption);
end;

procedure TfrmMain.RzGroup2Items0Click(Sender: TObject);
begin
    showform(WorkPage,TfrmCropKPI,TRzGroupItem(Sender).Caption);
end;

procedure TfrmMain.RzGroup2Items1Click(Sender: TObject);
begin
   showform(WorkPage,TfrmWeatherKPI,TRzGroupItem(Sender).Caption);
end;

procedure TfrmMain.RzGroup1Items2Click(Sender: TObject);
begin
   showform(WorkPage,TfrmSimuArith,TRzGroupItem(Sender).Caption);
end;

end.
